//
//  UIManager.h
//  Voxper
//
//  Created by Erphan on 2/7/11.
//  Copyright 2011 Smonte. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "WebProxy.h"
#import <AddressBook/AddressBook.h>
#import <AVFoundation/AVFoundation.h>

@class VoxperAppDelegate;
@class Settings;
@class DatabaseManager;
@class RecentCallItem;

@interface UIManager : NSObject<WebProxyDelegate, AVAudioPlayerDelegate> {
	VoxperAppDelegate *app;
	Settings *settings;
	DatabaseManager *dbManager;
	WebProxy *proxy;
	
#pragma mark -
#pragma mark DataStore :D
	NSMutableArray *countries;
	NSMutableArray *contacts;
	NSMutableArray *m_Conversations;
	NSMutableArray *m_RecentCalls;
	// this will hold recent call item and save it to db when call disconnect event fires;
	RecentCallItem *m_RecentCall;
	BOOL m_bCallingUILaunched;
	BOOL m_bContactListSent;
}


@property (nonatomic, retain) Settings *settings;
@property (nonatomic, retain) DatabaseManager *dbManager;

#pragma mark -
#pragma mark Nofitcations
- (void)handleCallStateChangedNotification:(NSNotification *)note;
- (void)handleRegistrationStateChangedNotification:(NSNotification *)note;
- (void)launchAnswerScreen:(NSString *)initalContactName; 

#pragma mark -
#pragma mark DataSource
- (NSMutableArray *)countriesList;
- (void)cleanCountriesList;
- (void)reloadContacts;
- (NSMutableArray *)getContacts;
- (void)reloadConversations;
- (void)reloadConversationsFromDatabase;
- (void)deleteConversationsAtIndexPaths:(NSArray *)indexPaths;
- (NSMutableArray *)getConversations;
- (NSMutableArray *)getConversation:(NSMutableArray *)arrayList fromPhone:(NSString *)fromPhon;
- (void)reloadRecentCalls;
- (NSMutableArray *)getRecentCalls;
- (BOOL)getSipContacts:(NSString *)strLocalId destinationArray:(NSMutableArray *)destinationArray;
- (void)clearRecentCalls;

#pragma mark -
#pragma mark WebServices
- (void)updateMyLocation;
- (void)registerPhone:(NSString *)phoneNumber;
- (void)registerPhone:(NSString *)phoneNumber withExistingVirtualNumber:(NSString *)virtualNumber;
- (void)verifyCode:(NSString *)passCode;
- (void)sendText:(NSString *)to :(NSString *)message;
- (void)getRecentCallsFromServer;
- (void)sendDeviceToken;

#pragma mark -
#pragma mark General Purpose Functions
- (void)handleApplicationDidFinishedLaunchingWithOptions:(NSDictionary *)launchOptions;
/// this method is used to trim extra internaional format characters like 00, 001, 011, +11
/// so that it can be used as login name for our system
- (NSString *)convertPhoneNumberInIntlFormat:(NSString *)strPhone :(BOOL)bAppendCountryCode;

/// this method converts any number to international format for view purpose only
- (NSString *)makePhoneNumberInIntlFormat:(NSString *)strPhone;
- (void)setContactsGroupSelection:(int)nSelectedIndex;
- (void)setRecentCallsSelection:(int)nSelectedIndex;
- (NSString *)getPrettyDate:(NSDate *)_date;
- (ABRecordRef)buildUnknownContactDetails:(NSString *)strPhoneNumber;
@end